// Mabel Xu

public ArrayList<Player> getPlayersInLineUp(ArrayList<Integer> bb)
{
	ArrayList<Player> lineup = new ArrayList<Player>();
	for (Integer i : bb)
		lineup.add(myTeam.get(i.intValue()));
	return lineup;
}

public boolean isLineUpValid(ArrayList<Player> lineup)
{
	int center_count = 0;
	int forward_count = 0;
	int guard_count = 0;
	
	for (Player p : lineup)
	{
		if (p.getPosition.equals("center"))
			center_count++;
		else if (p.getPosition.equals("forward"))
			forward_count++;
		else if (p.getPosition.equals("guard"))
			guard_count++;
	}
	
	return ((center_count + forward_count + guard_count) == lineup.size()) &&
			((center_count == 1) && (forward_count == 2) && (guard_count == 2));
}

public void printValidStartingTeam()
{
	int count = 1;
	CombinationGenerator cg = new CombinationGenerator(numberInLineUp, 0, myTeam.size() - 1);
	while(cg.hasMoreElements())
	{
		ArrayList<Player> possibleTeam = this.getPlayersInLineUp(cg.nextElement());
		if (this.isLineUpValid(possibleTeam) == true)
		{	
			// since this is a valid possible team, output it to the screen
			System.out.println("possibility #1: ");
			for (Player p : possibleTeam)
				System.out.println(p);
			System.out.println();
		}
	}
}

/* the class Team is an abstract class since it has an abstract method: isLineUpValid()
it makes sense for this particular method to be abstract since the requirements that determine whether a lineup is valid or not
would naturally vary from team to team, depending on what kind of team it is, whether it be a tennis team or a basketball team. */

public String toString()
{	
	// since polynomials are written with highest term first, use in-order traversal ... backwards
	Iterator iter = poly.keySet().iterator();
	Stack<Integer> reverser = new Stack<Integer>();
	while (iter.hasNext())
		reverser.push(iter.next());
	
	// now that we have a stack with biggest term on top, lets pop one by one and construct the string
	String output = "";
	while (!reverser.isEmpty())
	{
		Interger power = reverser.pop();
		output += poly.get(power).intValue() + "x^" + power.intValue() + " + ";
	}
	
	// trim off the extra " + " at the end and return the string
	output = output.subString(0, output.size() - 4);
	return output;
}

// needs to import Java's Math library ... I think this is the correct one but I'm not sure ...  >:(
import java.lang.Math;
public double evaluatePolynomial(double x)
{
	Iterator iter = poly.keySet().iterator();
	double answer = 0.0;
	while (iter.hasNext())
	{
		Integer power = iter.keySet().next();
		answer += poly.get(power) * Math.pow(x, power.intValue());
	}
	
	return answer;
}

public Polynomial add(Polynomial other)
{
	Iterator iter1 = poly.keySet().iterator();
	Iterator iter2 = other.keySet().iterator();
	Polynomial result = new Polynomial();
	
	// queues seem to be the best ways to handle shuffling two "lists" into one (since they have the ability to see the next one without "advancing", so convert both polynomials into queues
	Queue<Integer> q1 = new ArrayList<Integer>();
	while (iter1.hasNext())
		q1.put(iter1.next());
	Queue<Integer> q2 = new ArrayList<Integer>();
	while (iter2.hasNext())
		q2.put(iter2.next());
	
	// now combine the two polynomials
	while (!q1.isEmpty() && !q2.isEmpty())	// while there's something left to combine ...
	{
		if (q1.peek().intValue() == q2.peek().intValue())
		{
			Integer power = q1.get(); q2.get();
			result.put(power, new Integer(poly.get(power).intValue() + other.get(power).intValue()));
		}
		else if (q1.peek().intValue() < q2.peek().intValue())
		{
			Integer power = q1.get();
			result.put(power, poly.get(power));
		}
		else if (q1.peek().intValue() > q2.peek.intValue())
		{
			Integer power = q2.get();
			result.put(power, other.get(power));
		}
	}
	if (!q1.isEmpty() && q2.isEmpty())	// if polynomial "other" runs out first ... aka "self" has more terms than "other"
	{
		while (!q1.isEmpty())
		{
			Integer power = q1.get();
			result.put(power, poly.get(power));
		}
	}
	else if (q1.isEmpty() && !q2.isEmpty())	// if polynomial "self" runs out first ... aka "other" has more terms than "self"
	{
		while (!q2.isEmpty())
		{
			Integer power = q2.get();
			result.put(power, other.get(power));
		}
	}
		
	// by now both queues should have been exhausted, with all terms combined / added properly
	return result;
}